include vendor/google/custom/build/map.mk

#########################################################################################
# prebuilt app per sku

# $(1): PROJECT
# $(2): SKUID
# $(3): MODULE_NAME
# $(4): SRC_FILE
# $(5): MODULE_OWNER
# $(6): PRIVILEGED_MODULE
# $(7): CERTIFICATE
# $(8): USES_LIBRARIES
define prebuilt-product-app-sku-internal
include $(CLEAR_VARS)
LOCAL_MODULE := $(1).$(2).$(3)
LOCAL_SRC_FILES := $(4)
LOCAL_MODULE_OWNER := $(5)
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_PRIVILEGED_MODULE := $(6)
LOCAL_PRODUCT_MODULE := true
LOCAL_CERTIFICATE := $(7)
LOCAL_OPTIONAL_USES_LIBRARIES := $(8)

$(if $(findstring true,$(6)),
LOCAL_MODULE_PATH:=$(TARGET_OUT_PRODUCT)/custom/$(1)/$(2)/priv-app,
LOCAL_MODULE_PATH:=$(TARGET_OUT_PRODUCT)/custom/$(1)/$(2)/app
)

include $(BUILD_PREBUILT)
endef


# $(1): MODULE_NAME
# $(2): SRC_FILES
# $(3): MODULE_OWNER
# $(4): USES_LIBRARIES
define prebuilt-product-app-sku
$(foreach product,$(PRODUCTS),
   $(foreach skuid,$($(product)),
		$(call prebuilt-product-app-sku-internal,$(product),$(skuid),$(1),$(2),$(3),false,PRESIGNED,$(4))
   )
)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILES
# $(3): MODULE_OWNER
# $(4): USES_LIBRARIES
define prebuilt-product-privapp-sku
$(foreach product,$(PRODUCTS),
   $(foreach skuid,$($(product)),
		$(call prebuilt-product-app-sku-internal,$(product),$(skuid),$(1),$(2),$(3),true,PRESIGNED,$(4))
   )
)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILES
# $(3): MODULE_OWNER
# $(4): USES_LIBRARIES
define prebuilt-product-privapp-platform-sku
$(foreach product,$(PRODUCTS),
   $(foreach skuid,$($(product)),
		$(call prebuilt-product-app-sku-internal,$(product),$(skuid),$(1),$(2),$(3),true,platform,$(4))
   )
)
endef

#########################################################################################
# prebuilt app per device

# $(1): PROJECT
# $(2): MODULE_NAME
# $(3): SRC_FILE
# $(4): MODULE_OWNER
# $(5): PRIVILEGED_MODULE
# $(6): CERTIFICATE
# $(7): USES_LIBRARIES
define prebuilt-product-app-device-internal
include $(CLEAR_VARS)
LOCAL_MODULE := $(1).$(2)
LOCAL_SRC_FILES := $(3)
LOCAL_MODULE_OWNER := $(4)
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_PRIVILEGED_MODULE := $(5)
LOCAL_PRODUCT_MODULE := true
LOCAL_CERTIFICATE := $(6)
LOCAL_OPTIONAL_USES_LIBRARIES := $(7)

$(if $(findstring true,$(6)),
LOCAL_MODULE_PATH:=$(TARGET_OUT_PRODUCT)/custom/$(1)/device/priv-app,
LOCAL_MODULE_PATH:=$(TARGET_OUT_PRODUCT)/custom/$(1)/device/app
)

include $(BUILD_PREBUILT)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILES
# $(3): MODULE_OWNER
# $(4): USES_LIBRARIES
define prebuilt-product-app-device
$(foreach product,$(PRODUCTS),
	$(call prebuilt-product-app-device-internal,$(product),$(1),$(2),$(3),false,PRESIGNED,$(4))
)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILES
# $(3): MODULE_OWNER
# $(4): USES_LIBRARIES
define prebuilt-product-privapp-device
$(foreach product,$(PRODUCTS),
	$(call prebuilt-product-app-device-internal,$(product),$(1),$(2),$(3),true,PRESIGNED,$(4))
)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILES
# $(3): MODULE_OWNER
# $(4): USES_LIBRARIES
define prebuilt-product-privapp-platform-device
$(foreach product,$(PRODUCTS),
	$(call prebuilt-product-app-device-internal,$(product),$(1),$(2),$(3),true,platform,$(4))
)
endef

#########################################################################################
# prebuilt etc per sku

# $(1): PROJECT
# $(2): SKUID
# $(3): MODULE_NAME
# $(4): SRC_FILE
# $(5): SUBDIR
define prebuilt-product-etc-sku-internal
include $(CLEAR_VARS)
LOCAL_MODULE := $(1).$(2).$(3)
LOCAL_SRC_FILES := $(4)
LOCAL_MODULE_TAGS  := optional
LOCAL_MODULE_SUFFIX := $(suffix $(4))
LOCAL_MODULE_CLASS := ETC
$(if $(5),
LOCAL_MODULE_PATH  := $(TARGET_OUT_PRODUCT)/custom/$(1)/$(2)/etc/$(5),
LOCAL_MODULE_PATH  := $(TARGET_OUT_PRODUCT)/custom/$(1)/$(2)/etc
)
include $(BUILD_PREBUILT)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILE
# $(3): SUBDIR
define prebuilt-product-etc-sku
$(foreach product,$(PRODUCTS),
   $(foreach skuid,$($(product)),
		$(call prebuilt-product-etc-sku-internal,$(product),$(skuid),$(1),$(2),$(3))
   )
)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILE
define prebuilt-product-etc-sysconfig-sku
$(foreach product,$(PRODUCTS),
   $(foreach skuid,$($(product)),
		$(call prebuilt-product-etc-sku-internal,$(product),$(skuid),$(1),$(2),sysconfig)
   )
)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILE
define prebuilt-product-etc-permissions-sku
$(foreach product,$(PRODUCTS),
   $(foreach skuid,$($(product)),
		$(call prebuilt-product-etc-sku-internal,$(product),$(skuid),$(1),$(2),permissions)
   )
)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILE
define prebuilt-product-etc-default-permissions-sku
$(foreach product,$(PRODUCTS),
   $(foreach skuid,$($(product)),
		$(call prebuilt-product-etc-sku-internal,$(product),$(skuid),$(1),$(2),default-permissions)
   )
)
endef

#########################################################################################
# prebuilt etc per device

# $(1): PROJECT
# $(2): MODULE_NAME
# $(3): SRC_FILE
# $(4): SUBDIR
define prebuilt-product-etc-device-internal
include $(CLEAR_VARS)
LOCAL_MODULE := $(1).$(2)
LOCAL_SRC_FILES := $(3)
LOCAL_MODULE_TAGS  := optional
LOCAL_MODULE_SUFFIX := $(suffix $(43))
LOCAL_MODULE_CLASS := ETC
$(if $(5),
LOCAL_MODULE_PATH  := $(TARGET_OUT_PRODUCT)/custom/$(1)/device/etc/$(4),
LOCAL_MODULE_PATH  := $(TARGET_OUT_PRODUCT)/custom/$(1)/device/etc
)
include $(BUILD_PREBUILT)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILE
# $(3): SUBDIR
define prebuilt-product-etc-device
$(foreach product,$(PRODUCTS),
	$(call prebuilt-product-etc-device-internal,$(product),$(1),$(2),$(3))
)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILE
define prebuilt-product-etc-sysconfig-device
$(foreach product,$(PRODUCTS),
	$(call prebuilt-product-etc-device-internal,$(product),$(1),$(2),sysconfig)
)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILE
define prebuilt-product-etc-permissions-device
$(foreach product,$(PRODUCTS),
	$(call prebuilt-product-etc-device-internal,$(product),$(1),$(2),permissions)
)
endef

# $(1): MODULE_NAME
# $(2): SRC_FILE
define prebuilt-product-etc-default-permissions-device
$(foreach product,$(PRODUCTS),
	$(call prebuilt-product-etc-device-internal,$(product),$(1),$(2),default-permissions)
)
endef

#########################################################################################
# build overlay per sku

# $(1): PROJECT
# $(2): SKUID
# $(3): MODULE_NAME
# $(4): RES_DIR
# $(5): MANIFEST_FILE_NAME
define build-product-overlay-sku-internal
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := $(1).$(2).$(3)
LOCAL_MODULE_TAGS := optional
LOCAL_PRODUCT_MODULE := true
LOCAL_RESOURCE_DIR := $(4)
LOCAL_SDK_VERSION = current
LOCAL_CERTIFICATE := platform

$(if $(5),
LOCAL_MANIFEST_FILE := $(5),
LOCAL_MANIFEST_FILE := AndroidManifest.xml
)

LOCAL_IS_RUNTIME_RESOURCE_OVERLAY := true
LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT)/custom/$(1)/$(2)/overlay
LOCAL_AAPT_FLAGS += \
    --no-resource-deduping \
    --no-resource-removal
include $(BUILD_SYSTEM)/package.mk
endef

# $(1): MODULE_NAME
# $(2): RES_DIR
# $(3): MANIFEST_FILE_NAME
define build-product-overlay-sku
$(foreach product,$(PRODUCTS),
   $(foreach skuid,$($(product)),
		$(call build-product-overlay-sku-internal,$(product),$(skuid),$(1),$(2),$(3))
   )
)
endef

#########################################################################################
# build overlay per device

# $(1): PROJECT
# $(2): SKUID
# $(3): MODULE_NAME
# $(4): RES_DIR
# $(5): MANIFEST_FILE_NAME
define build-product-overlay-device-internal
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := $(1).$(2)
LOCAL_MODULE_TAGS := optional
LOCAL_PRODUCT_MODULE := true
LOCAL_RESOURCE_DIR := $(3)
LOCAL_SDK_VERSION = current
LOCAL_CERTIFICATE := platform

$(if $(5),
LOCAL_MANIFEST_FILE := $(5),
LOCAL_MANIFEST_FILE := AndroidManifest.xml
)

LOCAL_IS_RUNTIME_RESOURCE_OVERLAY := true
LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT)/custom/$(1)/device/overlay
LOCAL_AAPT_FLAGS += \
    --no-resource-deduping \
    --no-resource-removal
include $(BUILD_SYSTEM)/package.mk
endef

# $(1): MODULE_NAME
# $(2): RES_DIR
# $(3): MANIFEST_FILE_NAME
define build-product-overlay-device
$(foreach product,$(PRODUCTS),
	$(call build-product-overlay-device-internal,$(product),$(1),$(2),$(3))
)
endef